<?php
namespace app\controller;

use app\model\User;

class TestRole{
    public function index(){
        $user = User::find(19);
        $roles = $user->Roles;
        //return json($role);
        foreach($roles as $role){
            echo $role->type.'<br>';
        }
    }
    public function add(){
        $user = User::find(76);
        
        //$user->roles()->save(['type'=>'管理员']);// 给用户增加管理员权限 会自动写入角色表和中间表数据
        //$user->roles()->save(1); //1是超级管理员
        //$user->roles()->attach(2);
        $user->roles()->detach(2);
    }
}